import { queryBnsSystem, addBnsSystem,removeBnsSystem,updateBnsSystem,updateKey} from '@/services/security/bnsSystem';

export default {
  namespace: 'bnsSystem',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },

    queryForm:{},

  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryBnsSystem, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addBnsSystem, payload);
      yield put({
        type: 'saveadd',
        payload: response,
      });
      if (callback) callback(response);
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removeBnsSystem, payload);
      yield put({
        type: 'saveremove',
        payload: response,
      });
      if (callback) callback(response);
    },
    *update({ payload, callback }, { call, put }) {
      const response = yield call(updateBnsSystem, payload);
      yield put({
        type: 'saveupdate',
        payload: response,
      });
      if (callback) callback(response);
    },  
    
    *updateKey({ payload, callback }, { call, put }) {
      const response = yield call(updateKey, payload);
      yield put({
        type: 'saveupdate',
        payload: response,
      });
      if (callback) callback(response);
    }, 
  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data || [],
      };
    },
  },
};
